﻿using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Read.API.Application.Command.MenuCommand;
using D.Medicalcare.Read.API.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace D.Medicalcare.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 菜单表显示
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPaging<MenuDTO>> GetMenu([FromQuery]GetMenuCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 角色菜单反填
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<RMDTO>>> GetRoleMenu([FromQuery] GetRoleMenuCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 菜单树状
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MenuTreeDTO>>> GetMenuList([FromQuery] GetMenuListCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取菜单下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Menu>>> QueryMenu([FromQuery]QueryMenuCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
